<?php
/**
 * mysql连接池
 *
 * @version 0.1
 */
namespace waf\client\pools;

use \waf\log\WLog;
use \waf\client\mysql\WMysqlClient;

class WMysqlPools
{

    /**
     * 弹出一个可用的mysql连接
     *
     * @param array $conf
     * @return fasle or Swoole\Coroutine\MySQL
     */
    public static function pop($conf = array())
    {
        $objRet  = false;

        if(self::checkMysqlConnectParams($conf))
        {
            $objWMysqlClient = new WMysqlClient($conf);
            if($objWMysqlClient->isConnect())
            {
                $objRet = $objWMysqlClient;
            }else{
                unset($objWMysqlClient);
            }
        }else{
            WLog::logInfo("conf error. conf = ".WLog::toJson($conf), __FILE__, __LINE__, __FUNCTION__);
        }

        return $objRet;
    }

    public static function push()
    {

    }

    /**
     * 检查mysql连接参数，是否正常设置
     *
     * @param array $conf
     * @return bool
     */
    protected static function checkMysqlConnectParams($conf = array())
    {
        $isRet  = false;

        if($conf['host'] && $conf['user'] && $conf['password'] && $conf['database'])
        {
            $isRet = true;
        }

        return $isRet;
    }
}
?>
